<?php defined('SYSPATH') OR die('No direct access allowed.');

class Image extends Image_Core{
	

	function maxcrop($width, $height, $force=FALSE, $top = 'center', $left = 'center')
	{
		//get image sizes
		$data = $this->image;
		
		//we don't resize smaller images unless it's forced
		if ( ! $force && $width>=$data['width'] && $height>$data['height']) 
		{
			return $this;
		}
			
		$m = min($data['width']/$width, $data['height']/$height);
		$w = round($data['width']/$m);
		$h = round($data['height']/$m);
		
		$this->resize($w, $h);
		
		//crop
		return $this->crop($width, $height, $top, $left);
	}
	
	/**
	 * http://forum.kohanaphp.com/comments.php?DiscussionID=674
	 * Works with GD library only as of yet
	 * 
	 * @param $image
	 * @param $transparency
	 * @param $left
	 * @param $top
	 * @return unknown_type
	 */
	public function watermark(Image $image, $transparency = 80, $left = null, $top = null)
	{
		if (is_null($left)) { $left = ($this->width - $image->width) / 2; }
		if (is_null($top)) { $top = ($this->height - $image->height) / 2; }
		$this->actions['watermark'] = array(
			'image' => $image,
			'transparency' => (int)$transparency,
			'left' => (int)$left,
			'top' => (int)$top );
		return $this;
	}
}